package main

import "fmt"

type TreeNode struct {
	Val   int
	Left  *TreeNode
	Right *TreeNode
}

//层序遍历:0ms 100%,2MB 4%
func mirrorTree1(root *TreeNode) *TreeNode {
	if root == nil {
		return nil
	}
	tmp := []*TreeNode{root}
	for len(tmp) > 0 {
		tmp[0].Left, tmp[0].Right = tmp[0].Right, tmp[0].Left
		if tmp[0].Left != nil {
			tmp = append(tmp, tmp[0].Left)
		}
		if tmp[0].Right != nil {
			tmp = append(tmp, tmp[0].Right)
		}
		tmp = tmp[1:]
	}
	return root
}

//递归:0ms 100%,2MB 100%
func mirrorTree(root *TreeNode) *TreeNode {
	if root == nil {
		return nil
	}
	left := mirrorTree(root.Left)
	right := mirrorTree(root.Right)
	root.Left = right
	root.Right = left
	return root
}

func main() {
	s := []int{0}
	fmt.Println(s[1:])
	fmt.Println(mirrorTree(&TreeNode{}))
	fmt.Println(mirrorTree1(&TreeNode{}))
}
